package com.liguo.whoisthespy.utils

import club.ddkx.duoduokaixin.util.ke
import io.realm.RealmObject
import liguo.views.BaseActivity

/**
 *
 * Created by Extends on 2017/6/15 15:29
 */
fun <T: RealmObject> BaseActivity.save(t:T, hasPrimaryKey:Boolean = true, success:()->Unit = {}, error:(e:Throwable)->Unit = {}){
    realm.executeTransactionAsync({if(hasPrimaryKey)it.copyToRealmOrUpdate(t) else it.copyToRealm(t)},success,{error(it)})
}

fun <T: RealmObject> BaseActivity.listSave(t:Iterable<T>,hasPrimaryKey:Boolean = true){
    realm.executeTransactionAsync({if(hasPrimaryKey)it.copyToRealmOrUpdate(t) else it.copyToRealm(t)},{ke("成功了")},{ke(it.message)})
}